home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / app_prefs.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  9.3 KB  |  210 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Utilities to manage the writing of the user application specific
  5. preferences files.
  6. '''
  7. __id__ = '$Id: app_prefs.py 4335 2008-11-17 18:13:53Z wwalker $'
  8. __version__ = '$Revision: 4335 $'
  9. __date__ = '$Date: 2008-11-17 13:13:53 -0500 (Mon, 17 Nov 2008) $'
  10. __copyright__ = 'Copyright (c) 2007-2008 Sun Microsystems Inc.'
  11. __license__ = 'LGPL'
  12. import os
  13. import orca_prefs
  14. import settings
  15.  
  16. class OrcaPrefs(orca_prefs.OrcaPrefs):
  17.     
  18.     def __init__(self, prefsDict, appName = None, appScript = None, keyBindingsTreeModel = None, pronunciationTreeModel = None):
  19.         '''Creates a new OrcaPrefs instance that will be used to write out
  20.         application specific preferences.
  21.  
  22.         Arguments:
  23.         - prefsDict: a dictionary where the keys are orca preferences
  24.           names and the values are the values for the preferences.
  25.         - appName: the application these preferences are for.
  26.         - appScript: the application script.
  27.         - keyBindingsTreeModel - key bindings tree model, or None if we are
  28.           writing out console preferences.
  29.         - pronunciationTreeModel - pronunciation dictionary tree model, or
  30.           None if we are writing out console preferences.
  31.         '''
  32.         orca_prefs.OrcaPrefs.__init__(self, prefsDict, keyBindingsTreeModel, pronunciationTreeModel)
  33.         self.appName = appName
  34.         self.appScript = appScript
  35.  
  36.     
  37.     def _writeKeyBindingsPreamble(self, prefs):
  38.         '''Writes the preamble to the  ~/.orca/app-settings/<APPNAME>.py
  39.         keyBindings section.'''
  40.         prefs.writelines('\n')
  41.         prefs.writelines('# Set up a user key-bindings profile\n')
  42.         prefs.writelines('#\n')
  43.         prefs.writelines('def overrideAppKeyBindings(script, keyB):\n')
  44.  
  45.     
  46.     def _writeAppKeyBindingsPostamble(self, prefs, appName, appScript):
  47.         '''Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py
  48.         keyBindings section.
  49.  
  50.         Arguments:
  51.         - prefs: file handle for application preferences.
  52.         - appName: the application these preferences are for.
  53.         - appScript: the application script.
  54.         '''
  55.         prefs.writelines('   return keyB')
  56.         prefs.writelines('\n\n')
  57.  
  58.     
  59.     def _writeAppKeyBindingsMap(self, prefs, appName, appScript, treeModel):
  60.         """Write to an application specific configuration file 'prefs', the
  61.         key bindings passed in the model treeModel.
  62.  
  63.         Arguments:
  64.         - prefs: file handle for application preferences.
  65.         - appName: the application these preferences are for.
  66.         - appScript: the application script.
  67.         - treeModel: key bindings treemodel.
  68.         """
  69.         self._writeKeyBindingsPreamble(prefs)
  70.         self._iterateKeyBindings(prefs, treeModel)
  71.         self._writeAppKeyBindingsPostamble(prefs, appName, appScript)
  72.  
  73.     
  74.     def _writePronunciationsPreamble(self, prefs):
  75.         '''Writes the preamble to the  ~/.orca/app-settings/<APPNAME>.py
  76.         pronunciations section.'''
  77.         prefs.writelines('\n')
  78.         prefs.writelines('# User customized application specific ')
  79.         prefs.writelines('pronunciation dictionary settings\n')
  80.         prefs.writelines('#\n')
  81.         prefs.writelines('import orca.pronunciation_dict\n\n')
  82.         prefs.writelines('def overridePronunciations(script, pronunciations):\n')
  83.  
  84.     
  85.     def _writePronunciationsPostamble(self, prefs):
  86.         '''Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py
  87.         pronunciations section.'''
  88.         prefs.writelines('    return pronunciations')
  89.         prefs.writelines('\n\n')
  90.         prefs.writelines('orca.settings.overridePronunciations = overridePronunciations')
  91.         prefs.writelines('\n')
  92.  
  93.     
  94.     def _writePronunciation(self, prefs, word, value):
  95.         '''Write out a single pronunciation entry to the
  96.         ~/.orca/app-settings/<APPNAME>.py settings file.
  97.  
  98.         Arguments:
  99.         - prefs: file handle for application specific preferences.
  100.         - word: the actual word to be pronunced.
  101.         - value: the replace string to use.
  102.         '''
  103.         prefs.writelines('    orca.pronunciation_dict.setPronunciation(' + repr(word) + ', ' + repr(value) + ', pronunciations)\n')
  104.  
  105.     
  106.     def _writePronunciationMap(self, prefs, treeModel):
  107.         """Write to configuration file 'prefs' the new application specific
  108.         pronunciation dictionary entries passed in the model treeModel.
  109.  
  110.         Arguments:
  111.         - prefs: file handle for application preferences.
  112.         - treeModel: pronunciation dictionary tree model.
  113.         """
  114.         self._writePronunciationsPreamble(prefs)
  115.         self._iteratePronunciations(prefs, treeModel)
  116.         self._writePronunciationsPostamble(prefs)
  117.  
  118.     
  119.     def _writeAppPreferencesPreamble(self, prefs, appName):
  120.         '''Writes the preamble to the ~/.orca/app-settings/<APPNAME>.py file.
  121.  
  122.         Arguments:
  123.         - prefs: file handle for application preferences.
  124.         - appName: the application name.
  125.         '''
  126.         prefs.writelines('# -*- coding: utf-8 -*-\n')
  127.         prefs.writelines('# %s.py - custom Orca application settings\n' % appName)
  128.         prefs.writelines('# Generated by orca.  DO NOT EDIT THIS FILE!!!\n')
  129.         prefs.writelines('# If you want permanent customizations that will not\n')
  130.         prefs.writelines('# be overwritten, edit %s-customizations.py.\n' % appName)
  131.         prefs.writelines('#\n')
  132.         prefs.writelines('import orca.settings\n')
  133.         prefs.writelines('import orca.acss\n')
  134.         prefs.writelines('\n')
  135.  
  136.     
  137.     def _writeAppPreferencesPostamble(self, prefs, appName):
  138.         '''Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py file.
  139.  
  140.         Arguments:
  141.         - prefs: file handle for application preferences.
  142.         - appName: the application name.
  143.         '''
  144.         prefs.writelines('\ntry:\n')
  145.         prefs.writelines('    __import__("app-settings.%s-customizations")\n' % appName)
  146.         prefs.writelines('except ImportError:\n')
  147.         prefs.writelines('    pass\n')
  148.  
  149.     
  150.     def writePreferences(self):
  151.         '''Creates the directory and files to hold application specific
  152.         user preferences.  Write out any preferences that are different
  153.         from the generic Orca preferences for this user. Note that callers
  154.         of this method may want to consider using an ordered dictionary so
  155.         that the keys are output in a deterministic order.
  156.  
  157.         Returns True if the user needs to log out for accessibility
  158.         settings to take effect.
  159.         '''
  160.         self._setupPreferencesDirs()
  161.         oldPrefsDict = orca_prefs.readPreferences()
  162.         orcaDir = settings.userPrefsDir
  163.         orcaSettingsDir = os.path.join(orcaDir, 'app-settings')
  164.         appFileName = '%s.py' % self.appName
  165.         prefs = open(os.path.join(orcaSettingsDir, appFileName), 'w')
  166.         self._writeAppPreferencesPreamble(prefs, self.appName)
  167.         for key in settings.userCustomizableSettings:
  168.             value = self._getValueForKey(self.prefsDict, key)
  169.             oldValue = self._getValueForKey(oldPrefsDict, key)
  170.             if oldValue != value:
  171.                 prefs.writelines('orca.settings.%s = %s\n' % (key, value))
  172.                 continue
  173.         
  174.         if self.keyBindingsTreeModel:
  175.             self._writeAppKeyBindingsMap(prefs, self.appName, self.appScript, self.keyBindingsTreeModel)
  176.         
  177.         if self.pronunciationTreeModel:
  178.             self._writePronunciationMap(prefs, self.pronunciationTreeModel)
  179.         
  180.         self.appScript.setAppPreferences(prefs)
  181.         self._writeAppPreferencesPostamble(prefs, self.appName)
  182.         prefs.close()
  183.         return False
  184.  
  185.  
  186.  
  187. def writePreferences(prefsDict, appName = None, appScript = None, keyBindingsTreeModel = None, pronunciationTreeModel = None):
  188.     '''Creates the directory and files to hold application specific
  189.     user preferences.  Write out any preferences that are different
  190.     from the generic Orca preferences for this user. Note that callers
  191.     of this method may want to consider using an ordered dictionary so
  192.     that the keys are output in a deterministic order.
  193.  
  194.     Arguments:
  195.     - prefsDict: a dictionary where the keys are orca preferences
  196.     names and the values are the values for the preferences.
  197.     - appName: the application these preferences are for.
  198.     - appScript: the application script.
  199.     - keyBindingsTreeModel - key bindings tree model, or None if we are
  200.     writing out console preferences.
  201.     - pronunciationTreeModel - pronunciation dictionary tree model, or
  202.     None if we are writing out console preferences.
  203.  
  204.     Returns True if the user needs to log out for accessibility settings
  205.     to take effect.
  206.     '''
  207.     orcaPrefs = OrcaPrefs(prefsDict, appName, appScript, keyBindingsTreeModel, pronunciationTreeModel)
  208.     return orcaPrefs.writePreferences()
  209.  
  210.